<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
	/* aes 256 encrypt
    * @param String $ostr
    * @param String $securekey
    * @param String $type encrypt, decrypt
    */
    function encrypt_type($ostr,$type='encrypt'){
        $str = encryption_aes($ostr, $type);
        return $str;
    }
    
    /**
     * [get_post_info 获取post数据]
     * @param  boolean $isJson [是否json]
     * @return [type]          [description]
     */
    function get_post_info($isJson = TRUE)
    {
        $post = (file_get_contents("php://input"));
        if($isJson){
            $post = trim($this->encrypt_type($post,'decrypt'));
            // var_dump($post);die;
            if(!empty($post)){
                $post = special_filter($post);
                if(!sql_filter($post)) $this->send_error(ERROR_TRANSMIT_VALUE);
                $post = json_decode($post,TRUE);
            }
        }
        return $isJson ? $post:$post;
    }

    function send_error($errorCode, $msg = '')
    {
        $res = array('code'=>$errorCode, 'data'=>array(), 'msg'=>$msg);
        $json = json_encode($res);
        return $json;
    }

    function to_json($status,$obj, $msg = '')
    {
        $res = array();
        $res['code'] = $status;
        if(!empty($obj)){
            $res['data'] = $obj;
        }else{
            $res['data'] = array();
        }
        $res['msg'] = $msg;

        $json = json_encode($res);
        return $json;
    }

    function return_msg($json)
    {
        $json = json_encode($json);
        $json = encrypt_type($json,'encrypt');
        echo $json;
        die();
    }